package com.wuzuqing.android.eightdiagrams.task;

import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaItem;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 26.7.24 3:30 PM
 * @Description: 请写描述
 */
public class QiMenDunJiaStep7Task extends IQiMenDunJiaTask{
    QiMenDunJiaModel model;

    public QiMenDunJiaStep7Task(QiMenDunJiaModel model) {
        this.model = model;
    }

    @Override
    public void handleTask() {
        List<QiMenDunJiaItem> list = model.getList();
        int[] gongArr = new int[9];
        List<String> menArr = new ArrayList<>(QiMenDunJiaModel.menArr);
        int menGongShu = model.getMenGongShu();
        if (menGongShu==5){
            menGongShu = 2;
        }
        QiMenDunJiaItem jiaItem = getDunJia(list, menGongShu);
        if (jiaItem != null) {
            jiaItem.setMen(model.getZhiMen());
            int index = listArr.indexOf(menGongShu);
            int menIndex = menArr.indexOf(model.getZhiMen()); // 7
            for (int j = 1; j < listArr.size(); j++) {
                gongArr[j] = listArr.get((index + j) % listArr.size());
                QiMenDunJiaItem temp = getDunJia(list, gongArr[j]);
                if (temp != null) {
                    int xingRealIndex = (menIndex + j) % 8;
                    //定八门
                    temp.setMen(menArr.get(xingRealIndex));
                }
            }
        }
    }
}
